﻿using System.Collections.Generic;
using AwesomeSlider.Models;
using Orchard;
using Orchard.ContentManagement;
using Orchard.Core.Routable.Models;

namespace AwesomeSlider.Services
{
    public interface ISliderService : IDependency
    {
        IContent Create();
        IEnumerable<SliderPart> Get();
        ContentItem Get(int id, VersionOptions versionOptions);

        void Delete(ContentItem slider);
    }

    public class SliderService : ISliderService
    {
        private readonly IContentManager _contentManager;

        public SliderService(IContentManager contentManager)
        {
            _contentManager = contentManager;
        }

        public IContent Create()
        {
            return _contentManager.New("SliderConfiguration");
        }

        public IEnumerable<SliderPart> Get()
        {
            return _contentManager.Query<SliderPart>()
                .Join<RoutePartRecord>()
                .OrderBy(br => br.Title)
                .List();
        }

        public ContentItem Get(int id, VersionOptions versionOptions)
        {
            return _contentManager.Get(id, versionOptions);
        }

        public void Delete(ContentItem album)
        {
            _contentManager.Remove(album);
        }
    }
}